package sort;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class BubbleSort {

    public static void main(String[] args) {
        BubbleSort bubbleSort = new BubbleSort();
        int[] nums=new int[10000];
        for(int i =0;i<nums.length;i++){
            nums[i]=(int)(Math.random()*10000);
        }
        long time1 = System.currentTimeMillis();
        bubbleSort.sort(nums);
        long time2 = System.currentTimeMillis();
        System.out.println(Arrays.toString(nums));
        System.out.println(time2-time1);
    }


    public void sort(int[] nums) {
        int length = nums.length;
        int temp = 0;
        for (int i = 1; i < length - 1; i++) {
            for (int j = length - 1; j >= i; j--) {
                if (nums[j] < nums[j - 1]) {
                    change(nums,j,j-1);
                }
            }
        }
    }

    public void change(int[] nums, int x, int y) {
        int temp = 0;
        temp = nums[x];
        nums[x] = nums[y];
        nums[y] = temp;
    }

}
